/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xinxi.dms.view;

import com.xinxi.dms.po.Room;
import com.xinxi.dms.po.Stay;
import com.xinxi.dms.service.ChangeServiceIMPL;
import com.xinxi.dms.service.IChangeService;
import com.xinxi.dms.service.IRoomService;
import com.xinxi.dms.service.RoomServiceIMPL;
import com.xinxi.dms.util.FrameUtil2;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author zhigu
 */
public class ChangeFrame_25 extends javax.swing.JInternalFrame {
    IChangeService changeService = new ChangeServiceIMPL();
    IRoomService roomService = new RoomServiceIMPL();
    /**
     * Creates new form ChangeFrame_25
     */
    public ChangeFrame_25() {
        initComponents();
        //获取表格的列
        TableColumn tabColumn = this.tabStay.getColumnModel().getColumn(8);
        //设置宽高
        tabColumn.setWidth(0);
        
        tabColumn.setMinWidth(0);
        
        tabColumn.setMaxWidth(0);
        //设置表格的表头 指的就是上面对应的要隐藏的列
        tabStay.getTableHeader().getColumnModel().getColumn(8).setMaxWidth(0);
        txtRoomid.setVisible(false);
        
        btnSave.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        btnSelect = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabStay = new javax.swing.JTable();
        txtUnitno = new javax.swing.JTextField();
        txtbuildingno = new javax.swing.JTextField();
        txtStuname = new javax.swing.JTextField();
        txtReason = new javax.swing.JTextField();
        txtRoomno = new javax.swing.JTextField();
        txtStuid = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        btnRoomTest = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        labshow = new javax.swing.JLabel();
        txtRoomid = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        boxunitno = new javax.swing.JComboBox<>();
        jLabel10 = new javax.swing.JLabel();
        boxroomno = new javax.swing.JComboBox<>();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("25号楼调房系统");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        btnSelect.setText("查询");
        btnSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelectActionPerformed(evt);
            }
        });

        tabStay.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "学生编号", "学生姓名", "学生性别", "学生院校", "楼号", "单元号", "房间号", "入住状态", "房间编号"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabStay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabStayMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabStay);
        if (tabStay.getColumnModel().getColumnCount() > 0) {
            tabStay.getColumnModel().getColumn(0).setResizable(false);
            tabStay.getColumnModel().getColumn(1).setResizable(false);
            tabStay.getColumnModel().getColumn(2).setResizable(false);
            tabStay.getColumnModel().getColumn(3).setResizable(false);
            tabStay.getColumnModel().getColumn(4).setResizable(false);
            tabStay.getColumnModel().getColumn(5).setResizable(false);
            tabStay.getColumnModel().getColumn(6).setResizable(false);
            tabStay.getColumnModel().getColumn(7).setResizable(false);
            tabStay.getColumnModel().getColumn(8).setResizable(false);
        }

        txtStuname.setEditable(false);

        txtStuid.setEditable(false);

        jLabel2.setText("学生编号：");

        jLabel3.setText("调房原因：");

        jLabel4.setText("单元号：");

        jLabel5.setText("房间号：");

        jLabel6.setText("学生姓名：");

        jLabel7.setText("楼号：");

        btnRoomTest.setText("检验房间");
        btnRoomTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRoomTestActionPerformed(evt);
            }
        });

        btnSave.setText("保存");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnCancel.setText("取消");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 0, 0));
        jLabel8.setText("注意：调房前先检验房间！");

        labshow.setForeground(new java.awt.Color(255, 0, 0));

        txtRoomid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtRoomidActionPerformed(evt);
            }
        });

        jLabel9.setText("单元号：");

        boxunitno.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "请选择", "一单元", "二单元", "三单元" }));
        boxunitno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxunitnoActionPerformed(evt);
            }
        });

        jLabel10.setText("房间号：");

        boxroomno.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "请选择" }));
        boxroomno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxroomnoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(boxunitno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(boxroomno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(88, 88, 88)
                .addComponent(btnSelect)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(16, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(409, 409, 409)
                        .addComponent(btnRoomTest)
                        .addGap(18, 18, 18)
                        .addComponent(btnSave)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancel)
                        .addGap(42, 42, 42))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtReason)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtStuid, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(txtStuname, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtbuildingno, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(11, 11, 11)
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(txtUnitno, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addComponent(labshow, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(11, 11, 11)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(txtRoomno, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtRoomid, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(boxroomno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnSelect))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(boxunitno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUnitno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStuname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtbuildingno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRoomno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStuid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(txtRoomid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labshow, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtReason, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnRoomTest)
                            .addComponent(btnCancel)
                            .addComponent(btnSave)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel8)))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectActionPerformed
        // TODO add your handling code here:
        String unitno = (String)this.boxunitno.getSelectedItem();
        String roomno = (String)this.boxroomno.getSelectedItem();
        List<Stay> list = changeService.findAll_25(unitno,roomno);
        refresh(list);
    }//GEN-LAST:event_btnSelectActionPerformed

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        FrameUtil2.framemap.remove(ChangeFrame_25.class.getName());
    }//GEN-LAST:event_formInternalFrameClosing

    private void txtRoomidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtRoomidActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtRoomidActionPerformed

    private void tabStayMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabStayMouseClicked
        // TODO add your handling code here:
        int row = this.tabStay.getSelectedRow();
        this.txtStuid.setText(this.tabStay.getValueAt(row, 0).toString());
        this.txtStuname.setText(this.tabStay.getValueAt(row, 1).toString());
        this.txtbuildingno.setText(this.tabStay.getValueAt(row, 4).toString());
        this.txtUnitno.setText(this.tabStay.getValueAt(row, 5).toString());
        this.txtRoomno.setText(this.tabStay.getValueAt(row, 6).toString());
        this.txtRoomid.setText(this.tabStay.getValueAt(row, 8).toString()); 
        
        btnSave.setEnabled(true);
    }//GEN-LAST:event_tabStayMouseClicked

    private void btnRoomTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRoomTestActionPerformed
        // TODO add your handling code here:
        String buildingno = this.txtbuildingno.getText();
        String unitno = this.txtUnitno.getText();
        String roomno = this.txtRoomno.getText();
        Room room = new Room(buildingno,unitno,roomno);
        Room result = changeService.test(room);
        
        if(result!=null){
            String rs = result.getRemarks();
        Integer remarks =Integer.parseInt(rs);
        Integer checknumber = result.getChecknumber();
            this.labshow.setText("该房间能住"+rs+"人，已经住了"+checknumber+"人，还能住"+(remarks-checknumber)+"人");
        }else
            this.labshow.setText("该房间不存在");
    }//GEN-LAST:event_btnRoomTestActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        // TODO add your handling code here:
        String boxunitno = (String)this.boxunitno.getSelectedItem();
        String boxroomno = (String)this.boxroomno.getSelectedItem();
        String sid = this.txtStuid.getText();
        Integer stuid = Integer.parseInt(sid);
        String stuname = this.txtStuname.getText();
        String buildingno = this.txtbuildingno.getText();
        String unitno = this.txtUnitno.getText();
        String roomno = this.txtRoomno.getText();
        String roid = this.txtRoomid.getText();
        Integer roomid = Integer.parseInt(roid);
        String changereason = this.txtReason.getText().trim();
        Stay stay = new Stay(roomid,stuid,changereason,stuname,buildingno,unitno,roomno);
        if(txtReason.getText().equals("")||txtReason.getText().length()==0){
            JOptionPane.showMessageDialog(this, "请输入调房原因");     
        }else{
            int result = changeService.update(stay);
            switch(result){
                case 0 :JOptionPane.showMessageDialog(this, "没有发生变化");break;
                case 1 :JOptionPane.showMessageDialog(this, "改名学生转宿成功");cancel();break;
                case 2 :JOptionPane.showMessageDialog(this, "转宿失败");break;
                case 3 :JOptionPane.showMessageDialog(this, "转入房间已满，请重试");break;
                case 4 :JOptionPane.showMessageDialog(this, "没有修改房间信息，请重试");break;
            }
        }
        List<Stay> list = changeService.findAll_25(boxunitno,boxroomno);
        refresh(list);
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        cancel();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void boxunitnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxunitnoActionPerformed
        // TODO add your handling code here:
        this.boxroomno.removeAllItems();
        //向单元号添加一个请选择
        this.boxroomno.addItem("请选择");
        //获取楼号组合框中的内容
        String unitno = (String)this.boxunitno.getSelectedItem();
        List<Room> roomlist = roomService.getRoom25(unitno);
        for(Room room : roomlist){
            this.boxroomno.addItem(room.getRoomno());
        }
    }//GEN-LAST:event_boxunitnoActionPerformed

    private void boxroomnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxroomnoActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_boxroomnoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox<String> boxroomno;
    private javax.swing.JComboBox<String> boxunitno;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnRoomTest;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSelect;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labshow;
    private javax.swing.JTable tabStay;
    private javax.swing.JTextField txtReason;
    private javax.swing.JTextField txtRoomid;
    private javax.swing.JTextField txtRoomno;
    private javax.swing.JTextField txtStuid;
    private javax.swing.JTextField txtStuname;
    private javax.swing.JTextField txtUnitno;
    private javax.swing.JTextField txtbuildingno;
    // End of variables declaration//GEN-END:variables

    private void refresh(List<Stay> list) {
        DefaultTableModel dtm = (DefaultTableModel) this.tabStay.getModel();
        while(dtm.getRowCount()>0){
            dtm.removeRow(0);
        }
        for(Stay s:list){
            Vector v = new Vector();
            v.add(s.getStuid());
            v.add(s.getStuname());
            v.add(s.getStusex());
            v.add(s.getStuschool());
            v.add(s.getBuildingno());
            v.add(s.getUnitno());
            v.add(s.getRoomno());
            v.add(s.getState());
            v.add(s.getRoomid());
            dtm.addRow(v);
        }
    }
    private void cancel(){
        this.txtStuid.setText("");
        this.txtStuname.setText("");
        this.txtbuildingno.setText("");
        this.txtUnitno.setText("");
        this.txtRoomno.setText("");
        this.txtReason.setText("");
        this.txtRoomid.setText("");
        
        btnSave.setEnabled(false);
    }
}
